import 'package:flutter/material.dart';
import 'package:local_coffee/components/c_button/index.dart';
import 'package:local_coffee/components/c_checkbox/index.dart';
import 'package:local_coffee/components/c_row/custom_row.dart';
import 'package:local_coffee/components/c_stepper/custom_stepper.dart';
import 'package:local_coffee/components/hex.dart';
import 'package:local_coffee/components/rgba.dart';
import 'package:local_coffee/jsonserialize/shopping_cart/data.dart';
import 'package:local_coffee/utils/global.dart';

class ShoppingCartRow extends StatelessWidget {
  
  final ShoppingCartData data;
  final bool border;
  final Function onChange;
  final Function(bool) onCheckBoxChange;

  /// 购物车商品列表行
  const ShoppingCartRow({
    Key key,
    this.data,
    this.border = true,
    @required this.onChange,
    @required this.onCheckBoxChange
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomRow(
      height: null,
      padding: EdgeInsets.symmetric(horizontal: 15),
      border: Border.all(color: Colors.transparent),
      leftChild: Container(
        margin: EdgeInsets.only(right: 15),
        child: CCheckBox(
          activeColor: RGBA.rgba88afd5,
          width: 24,
          radius: Radius.circular(24),
          value: data.checked,
          onChanged: (bool value) => onCheckBoxChange(value),
        ),
      ),
      centerChild: Container(
        padding: EdgeInsets.symmetric(vertical: 15),
        decoration: BoxDecoration(
          border: G.borderBottom(show: border)
        ),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          '${data.name}',
                          style: TextStyle(
                            color: RGBA.rgba383838,
                            fontWeight: FontWeight.bold,
                            fontSize: 15
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 5),
                          child: CButton.normal(
                            child: Text(
                              '充二送一',
                              style: TextStyle(
                                fontSize: 8
                              ),
                            ),
                            bgColor: RGBA.rgbaff8102,
                            color: HEX.hexfff,
                            height: 16,
                            width: 34,
                            borderRadius: BorderRadius.circular(2),
                            onPressed: () => {}
                          ),
                        )
                      ],
                    ),
                    Row(
                      children: <Widget>[
                        Text(
                          '${G.handleGoodsDesc(data.specName)}',
                          style: TextStyle(
                            color: RGBA.rgba505050,
                            fontSize: 10
                          ),
                        )
                      ],
                    ),
                    Row(
                      children: <Widget>[
                        Text(
                          '仅限打包',
                          style: TextStyle(
                            color: RGBA.rgba557a9d,
                            fontSize: 10
                          ),
                        )
                      ],
                    )
                  ],
                ),
              ),
            ),
            Text(
              '￥ ${data.price}',
              style: TextStyle(
                color: RGBA.rgba383838,
                fontSize: 18,
                fontWeight: FontWeight.bold
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 10),
              child: CustomStepper(
                value: data.number,
                onChange: (val) => onChange(val),
              ),
            )
          ],
        ),
      ),
    );
  }
}